import create from '../../utils/create2.js'
import SystemUtil from '../../shell/system/system.js';
create({
  /**
   * 组件的属性列表
   */
  properties: {
    tips: {
      type: String,
      value: '加载更多'
    },
    load: {
      type: Boolean,
      value: false
    }
  },
  options: {
    multipleSlots: true
  },
  ready() {
    const query = wx.createSelectorQuery();
    //获取系统,设备信息
    let deviceInfo = SystemUtil.getSystemInfo(false)
    query.select('#header').boundingClientRect(area => {
      const {
        windowHeight
      } = deviceInfo
      const {
        height
      } = area
      let {
        h
      } = this.data
      this.setData({
        h: h ? windowHeight - height - h : windowHeight - height
      })
    }).exec()
  },
  /**
   * 组件的初始数据
   */
  data: {
    showLoad: true,
    scrollTop: 0,
    h: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    upper() {
      const {
        showLoad
      } = this.data
      if (showLoad) {
        this.triggerEvent('upper')
      }
    },
    lower() {
      const {
        load
      } = this.data
      if (load) return
      this.setData({
        load: true,
        tips: '数据加载中...'
      })
      this.triggerEvent('lower')
    },
    hideLoading() {
      setTimeout(() => {
        this.setData({
          showLoad: true
        })
      }, 2500)
    },
    showLoading() {
      this.setData({
        showLoad: false
      })
    },
    scrollHandler(e) {
      this.setData({
        scrollTop: e.detail.scrollTop
      })
    },
    minusHeight(val) {
      let {
        h
      } = this.data
      this.setData({
        h: h ? h - val : val
      })
    }
  }
})